package com.alisveris.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.alisveris.pojo.UrunDetayPojo;
import com.dbConnector.DataBaseConnector;

public class UrunDetayDao extends DataBaseConnector {

	/**
	 * ERKAN YILDIRIM
	 */
	private static final long serialVersionUID = 1L;

	public UrunDetayPojo getRetrieveProductInfo(String urunKod) throws Exception {

		UrunDetayPojo urunInfo = new UrunDetayPojo();

		String selectSQL = "SELECT * FROM product_info i, product p where i.product_id=p.id and p.kod=?";

		PreparedStatement preparedStatement = null;

		try {
			getDBConnection();

			preparedStatement = getDbConnection().prepareStatement(selectSQL);
			preparedStatement.setString(1, urunKod);
			
			ResultSet resultSet = preparedStatement.executeQuery();

			while (resultSet.next()) {

				

				urunInfo.setKod(resultSet.getString("KOD"));
				urunInfo.setIsmi(resultSet.getString("ISMI"));
				urunInfo.setProductAbout(resultSet.getString("PRODUCT_ABOUT"));
				
				
				if (resultSet.getString("MIKTAR") != null) {
					int miktar = Integer.parseInt(resultSet.getString("MIKTAR"));
					urunInfo.setMiktar(miktar);
				}

				if (resultSet.getString("TALEP_MIKTAR") != null) {
					int talepMiktari = Integer.parseInt(resultSet.getString("TALEP_MIKTAR"));
					urunInfo.setTalepMiktar(talepMiktari);
				}

				if (resultSet.getString("FIYAT") != null) {
					float fiyat = Float.parseFloat(resultSet.getString("FIYAT"));
					urunInfo.setFiyat(fiyat);
				}

				

			}

		} catch (SQLException e) {
			e.printStackTrace();

		} finally {

			if (preparedStatement != null) {
				preparedStatement.close();
			}

			if (getDbConnection() != null) {
				getDbConnection().close();
			}
		}

		return urunInfo;

	}

}
